﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace Saxxon.LibDoomSharp
{
    /// <summary>
    /// A static class that provides functionality to calculate checksums using a variety of methods.
    /// </summary>
    static public class Checksum
    {
        /// <summary>
        /// Convert a byte array to a hex string representation.
        /// </summary>
        static string ByteArrayToString(byte[] data)
        {
            return BitConverter.ToString(data).Replace("-", "");
        }

        /// <summary>
        /// Get the MD5 checksum of a byte array.
        /// </summary>
        static public string GetMD5(byte[] data)
        {
            MD5 algo = MD5.Create();
            byte[] hash = algo.ComputeHash(data);
            return ByteArrayToString(hash);
        }

        /// <summary>
        /// Get the SHA1 checksum of a byte array.
        /// </summary>
        static public string GetSHA1(byte[] data)
        {
            SHA1 algo = SHA1.Create();
            byte[] hash = algo.ComputeHash(data);
            return ByteArrayToString(hash);
        }
    }
}
